package org.hot100_2;

import java.util.HashSet;

public class leetcode160 {
    public ListNode getIntersectionNode(ListNode headA,ListNode headB){
        HashSet<ListNode> set = new HashSet<>();

        ListNode temp = headA;

        while (temp!=null){
            set.add(temp);
            temp=temp.next;
        }

        temp=headB;

        while (temp!=null){
            if (set.contains(temp)){
                return temp;
            }
        temp=temp.next;
        }

        return null;
    }
}
